//
//  YCSpecialTrainingCell.m
//  YCSchool
//
//  Created by Kylin on 16/5/3.
//  Copyright © 2016年 yanglinxia. All rights reserved.
// 专项训练的tableViewCell 

#import "YCSpecialTrainingCell.h"
#import "YCTrainingCell.h"
@interface YCSpecialTrainingCell()<UICollectionViewDataSource,UICollectionViewDelegate>
/**标签数组*/
@property(nonatomic,strong)NSMutableArray *titleArray;
/**图标数组*/
@property(nonatomic,strong)NSMutableArray *imageArray;

/**collectionView*/
@property(nonatomic,strong)UICollectionView *specialTrainingView;
/**布局*/
@property(nonatomic,strong)UICollectionViewFlowLayout *layout;

@end

static NSInteger const columnOfRow = 4;
static NSInteger const cellHight = 82;
static NSString *const TrainingCell = @"TrainingCell";
@implementation YCSpecialTrainingCell
+ (CGFloat)getCellHeight{
    return 167;
}

// 数据数组
- (NSMutableArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSMutableArray arrayWithArray:@[@"半坡起步",@"侧位停车",@"曲线行驶",@"直角转弯",@"倒车入库"]];
    }
    
    return _titleArray;
}

- (NSMutableArray *)imageArray{
    if (!_imageArray) {
        _imageArray = [NSMutableArray arrayWithArray:@[@"半坡起步",@"侧位停车",@"曲线行驶",@"直角转弯",@"倒车入库"]];
    }
    
    return _imageArray;
}

// 懒加载collectionView
- (UICollectionView *)specialTrainingView{
        if (!_specialTrainingView) {
            UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
            layout.scrollDirection = UICollectionViewScrollDirectionVertical;
            layout.minimumInteritemSpacing = 0;
            layout.minimumLineSpacing = 0;
            layout.itemSize = CGSizeMake(kScreenWidth/ columnOfRow, cellHight);
            _specialTrainingView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, (cellHight * 2 + 6)) collectionViewLayout:layout];
            [self.contentView addSubview:_specialTrainingView];
//            _specialTrainingView.backgroundColor = [UIColor blueColor];
            _specialTrainingView.dataSource = self;
            _specialTrainingView.delegate = self;
            _specialTrainingView.pagingEnabled = YES;
            _specialTrainingView.backgroundColor = [UIColor whiteColor];
            _specialTrainingView.showsHorizontalScrollIndicator = NO;
            _specialTrainingView.showsVerticalScrollIndicator = NO;
            [_specialTrainingView registerClass:[YCTrainingCell class] forCellWithReuseIdentifier:TrainingCell];
    }
        return _specialTrainingView;
}


// 重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor lightGrayColor];
        [self setupChildView];
    }
    return self;
}

- (void)setupChildView{
    
    [self specialTrainingView];
}

#pragma mark- collectionDataSource 方法

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YCTrainingCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:TrainingCell forIndexPath:indexPath];
    cell.title = self.titleArray[indexPath.row];
    cell.image = self.imageArray[indexPath.row];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.titleArray.count ;
}


#pragma mark- collectionDelegate 方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YCLog(@"%zd",indexPath.row);
}

@end

